﻿using System.Collections.Generic;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UITabItemTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetIsSelectedProperty()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem1 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 1'");
            Assert.IsTrue(tabItem1.IsSelected);
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            Assert.IsFalse(tabItem2.IsSelected);
        }

        [TestMethod]
        public void ShouldSelect()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem1 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 1'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            Assert.IsTrue(tabItem1.IsSelected);
            Assert.IsFalse(tabItem2.IsSelected);
            tabItem2.Select();
            Assert.IsFalse(tabItem1.IsSelected);
            Assert.IsTrue(tabItem2.IsSelected);
        }

        [TestMethod]
        public void ShouldGetSelectionContainer()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem1 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 1'");
            AutomationElement selectionContainer = tabItem1.GetSelectionContainer(); 
            Assert.IsNotNull(selectionContainer);
            Assert.AreEqual("tabControl1", selectionContainer.Current.AutomationId);
        }

        [TestMethod]
        public void ShouldGetAllTabItems()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            List<UITabItem> tabItems = window.UITab("@AutomationId='tabControl1'").UITabItems();
            Assert.AreEqual(2, tabItems.Count);
            Assert.AreEqual("Tab 1", tabItems[0].Name);
            Assert.AreEqual("Tab 2", tabItems[1].Name);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}